package com.mxx.common.flow;

import com.mxx.common.exception.UnImplementedException;

/**
 * @author: mxx
 * @date: 2021/12/29
 * @time: 17:03
 * @Description: 描述信息
 */
public interface Flow {

    String flowName();

    default void init(FlowContext context) {
        context.next();
    }

    void execute(FlowContext context);

    default void complete(FlowContext context) {
        context.next();
    }

    default void canException(FlowContext context, Throwable throwable) {
        context.next();
    }


    public static final Flow NIL_FLOW = new Flow() {
        @Override
        public String flowName() {
            return "NIL_FLOW";
        }

        @Override
        public void execute(FlowContext context) {

        }


    };
    public static final Flow EXCEPTION_FLOW = new Flow() {
        @Override
        public String flowName() {
            return "EXCEPTION_FLOW";
        }

        @Override
        public void execute(FlowContext context) {
            throw new UnImplementedException("nil flow complete UnImplemented");
        }

    };

}
